<?php
namespace app\rbac;

use yii\base\BootstrapInterface;
use app\base\classes\Hook;
use app\system\enums\ModuleGroupEnmu;
use app\module\BaseModule;
use app\base\helpers\Util;

class Module extends BaseModule implements BootstrapInterface
{

    const EVENT_RBAC_PERMISSION = "EVENT_RBAC_PERMISSION";

    const SUPER_PERMISSION = "*";

    public $authRules = [
        [
            "name" => "disabled-post",
            "class" => '\app\rbac\rules\DisabledPost',
            "description" => "禁用Post请求"
        ]
    ];

    public function init()
    {
        parent::init();
    }

    public function bootstrap($app)
    {
        Hook::on(\app\system\Module::EVENT_SYSTEM_GROUPNAV, [
            $this,
            "onSetGroupNav"
        ]);
        
        Util::setComponent("authManager", [
            "class" => "\\app\\rbac\\components\\DbManager"
        ]);
        
        Hook::on(new \app\rbac\hooks\Permission());
    }

    /**
     *
     * @param \app\base\helpers\Event $event
     */
    public function onSetGroupNav($event)
    {
        $event->parameters->set(ModuleGroupEnmu::PEOPLE, [
            [
                'label' => "用户分组",
                'icon' => "fa-users",
                'url' => [
                    "/rbac/role/index"
                ]
            ],
//             [
//                 'label' => "权限生成",
//                 'icon' => "fa-users",
//                 'url' => [
//                     "/rbac/tool/index"
//                 ]
//             ]
        ]);
    }
}